﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Presentation.Models.SubprojectViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	New Subproject
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>New Subproject</h2>
    <!--<font style="color: #FF0000"><b><%: Model.errmsg %></b></font>-->
    <% using (Html.BeginForm("Create", "Subproject", FormMethod.Post))
       {%>

                <div>
                
                    <table>
                        
                        <tr>
                            <td>
                                 <%: Html.LabelFor(m => m.Subproject.Name) %>
                            </td>
                            <td>
                                <%: Html.TextBoxFor(m => m.Subproject.Name)%>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <%: Html.LabelFor(m => m.Subproject.Description)%>
                            </td>
                            <td>
                                <%: Html.TextBoxFor(m => m.Subproject.Description)%>
                            </td>
                        </tr>

                        <% 
           
                            foreach (var formElement in Model.Form.FormElements)
                            {
                                var index = Model.Subproject.GetDetailIndex(formElement.Name);
                                var error = " ";

                                if (Model.errmsg != null && Model.errindex == index)
                                    error = Model.errmsg;
                        
                                if (index != -1)
                                {
                                    var detail = Model.Subproject.Details[index];
                            
                                    if (formElement.Type.Equals(Domain.Model.FormElement.TYPE_CHAR))
                                    { 
                                    %>
                                        
                                        <tr>
                                            
                                            <td>
                                            <%: Html.Label(Model.Subproject.Details[index].Name)%>
                                            </td>
                                            <td>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Id", detail.Id)%>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Name", detail.Name)%>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Description", detail.Description)%>
                                                <%: Html.TextBox("Subproject.Details[" + index + "].Value", detail.Value)%>
                                                 <font style="color: #FF0000"><b><%:error %></b></font> 
                                            </td>

                                        </tr>
                                        
                                    <%
                                    }
                                    if (formElement.Type.Equals(Domain.Model.FormElement.TYPE_NUMERIC))
                                    {
                                    %>
                                        
                                        <tr>
                                            
                                            <td>
                                            <%: Html.Label(Model.Subproject.Details[index].Name)%>
                                            </td>
                                            <td>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Id", detail.Id)%>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Name", detail.Name)%>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Description", detail.Description)%>
                                                <%: Html.TextBox("Subproject.Details[" + index + "].Value", detail.Value)%>
                                                 <font style="color: #FF0000"><b><%:error %></b></font> 
                                            </td>

                                        </tr>
                                        
                                    <%
                                    }
                                    if (formElement.Type.Equals(Domain.Model.FormElement.TYPE_DATE))
                                    {
                                    %>
                                        
                                        <tr>
                                            
                                            <td>
                                            <%: Html.Label(Model.Subproject.Details[index].Name)%>
                                            </td>
                                            <td>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Id", detail.Id)%>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Name", detail.Name)%>
                                                <%: Html.Hidden("Subproject.Details[" + index + "].Description", detail.Description)%>
                                                <%: Html.TextBox("Subproject.Details[" + index + "].Value", detail.Value)%>
                                                 <font style="color: #FF0000"><b><%:error %></b></font> 
                                            </td>

                                        </tr>
                                        
                                    <%
                                    }
                                }
                            }
                    
                        %>

                    </table>

                <p>
                     <%: Html.Hidden("ProjectId", Model.ProjectId)%>
                     <%: Html.Hidden("Subproject.Id", Model.Subproject.Id)%>
                    <input type="submit" value="Create" />
                </p>

        </div>

    <% } %>

    <div>
        <%: Html.ActionLink("Cancel", "Index", "Portfolio") %>
    </div>

</asp:Content>
